//
//  GoodsStatusView.m
//  jingdongfang
//
//  Created by MTiMac02 on 2018/1/13.
//  Copyright © 2018年 LJL. All rights reserved.
//

#import "GoodsStatusView.h"
#import "KLCPopup.h"
#import "RefundApplyVC.h"


@interface GoodsStatusView ()
{
    UILabel *name;
    UIButton *noGoods;
    UIButton *haveGoods;
    UIButton *confirmBtn;
}
@end
@implementation GoodsStatusView
+ (GoodsStatusView *)goodsStatusView {
    GoodsStatusView *goodsView = [[GoodsStatusView alloc] initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, 200)];
    goodsView.backgroundColor = [UIColor whiteColor];
    goodsView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    goodsView.layer.borderWidth = 1.0;
    return goodsView;
}

- (void)show {
    KLCPopup *pop = [KLCPopup popupWithContentView:self showType:KLCPopupShowTypeNone dismissType:KLCPopupDismissTypeSlideOutToBottom maskType:KLCPopupMaskTypeDimmed dismissOnBackgroundTouch:YES dismissOnContentTouch:NO];
    [pop show];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self loadUI];
    }
    return self;
}

- (void)loadUI
{
    self.backgroundColor = [UIColor c4Color];
    name = [[UILabel alloc] init];
    name.font = [UIFont font18];
    name.textAlignment = NSTextAlignmentCenter;
    name.backgroundColor = [UIColor whiteColor];
    name.textColor = [UIColor c4Color];
    name.text =NSLocalizedString(@"Goods Status", nil);
    [name sizeToFit];
    [self addSubview:name];
    
    noGoods=[UIButton buttonWithType:UIButtonTypeCustom];
    [noGoods setTitle:NSLocalizedString(@"Goods Not Received", nil) forState:UIControlStateNormal];
    [noGoods setTitle:NSLocalizedString(@"Goods Not Received", nil) forState:UIControlStateSelected];
    [noGoods sizeToFit];
    noGoods.contentEdgeInsets=UIEdgeInsetsMake(5, 10, 5, 10);
    noGoods.titleLabel.textAlignment=NSTextAlignmentCenter;
    noGoods.layer.cornerRadius=15;
    noGoods.layer.borderWidth=1.0;
    [noGoods setTitleColor:[UIColor c4Color] forState:UIControlStateNormal];
    [noGoods setTitleColor:[UIColor appColor] forState:UIControlStateSelected];
    [noGoods setSelected:YES];
    if (noGoods.selected)
    {
        noGoods.layer.borderColor=[UIColor appColor].CGColor;
        
    }else
    {
        noGoods.layer.borderColor=[UIColor c4Color].CGColor;
    }
    noGoods.titleLabel.font = [UIFont font16];
    [noGoods addTarget:self action:@selector(noGoodsBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:noGoods];
    
    haveGoods=[UIButton buttonWithType:UIButtonTypeCustom];
    [haveGoods setTitle:NSLocalizedString(@"Goods Received", nil) forState:UIControlStateNormal];
    [haveGoods setTitle:NSLocalizedString(@"Goods Received", nil) forState:UIControlStateSelected];
    [haveGoods sizeToFit];
    haveGoods.contentEdgeInsets=UIEdgeInsetsMake(5, 10, 5, 10);
    haveGoods.titleLabel.textAlignment=NSTextAlignmentCenter;
    haveGoods.layer.cornerRadius=15;
    if (haveGoods.selected)
    {
        haveGoods.layer.borderColor=[UIColor appColor].CGColor;
    }else
    {
        haveGoods.layer.borderColor=[UIColor c4Color].CGColor;
    }
    haveGoods.layer.borderColor=[UIColor c4Color].CGColor;
    haveGoods.layer.borderWidth=1.f;
    [haveGoods setTitleColor:[UIColor c4Color] forState:UIControlStateNormal];
    [haveGoods setTitleColor:[UIColor appColor] forState:UIControlStateSelected];
    [haveGoods setSelected:NO];
    haveGoods.titleLabel.font = [UIFont font16];
    [haveGoods addTarget:self action:@selector(haveGoodsBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:haveGoods];
    
    confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [confirmBtn addTarget:self action:@selector(confirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
    confirmBtn.backgroundColor = [UIColor appColor];
//    [confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
    [confirmBtn setTitle:NSLocalizedString(@"Confirm", nil) forState:UIControlStateNormal];
    confirmBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
    [self addSubview:confirmBtn];
    CGFloat gap=(KSCREENWIDTH-noGoods.width-haveGoods.width)/3;
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(20);
    }];
    [noGoods mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(name.bottom+50);
        make.left.mas_equalTo(gap-15);
    }];
    [haveGoods mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(name.bottom+50);
        make.right.mas_equalTo(-(gap-15));
    }];
    
    [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.bottom).mas_offset(0);
        make.width.mas_equalTo(KSCREENWIDTH);
        make.height.mas_equalTo(44);
    }];

}
-(void)noGoodsBtnClick:(UIButton *)btn
{
    [btn setSelected:YES];
    [haveGoods setSelected:NO];
    btn.layer.borderColor=[UIColor appColor].CGColor;
    haveGoods.layer.borderColor=[UIColor c4Color].CGColor;
}
-(void)haveGoodsBtnClick:(UIButton *)btn
{
    [btn setSelected:YES];
    [noGoods setSelected:NO];
    btn.layer.borderColor=[UIColor appColor].CGColor;
    noGoods.layer.borderColor=[UIColor c4Color].CGColor;
}


- (void)confirmBtnClick
{
    __weak typeof(self) weakself = self;

    if (noGoods.isSelected) {
        weakself.state=@"1";
     
    }else{
        weakself.state=@"2";
    }
    if (weakself.returnBlock) {
        weakself.returnBlock(weakself.state);
    }

    [KLCPopup dismissAllPopups];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
